<cfcomponent>
	<cffunction name="set">
		<cfargument name="varName" required="true" type="string">
		<cfargument name="varValue" required="true" type="any">

		<cflock scope="Session" throwontimeout="true" timeout="7" type="exclusive">
			<cfif isStruct(arguments.varValue)>
				<cfset "session.#arguments.varName#" = structCopy(arguments.varValue)>
			<cfelse>
				<cfset "session.#arguments.varName#" = arguments.varValue>
			</cfif>
		</cflock>

		<cfreturn>
	</cffunction>
<!--- START FRAMEWORK UTILITY FUNCTIONS --->
	<cffunction name="catchORMformSubmit" hint="this function is trigger by the existence of form.ORM in a request">
		<!---
			we attempt to build an object, based on the form contents...
			...then trigger the associated save event
			note: loading ORM objects can be done via implicit events named: loadObjName (see tags/triggerEvent.cfm)
		--->

		<cfargument name="formScope" required="true" type="struct">

		<cfset thisObject = createObject("#formScope.ORM#")>
		<cfloop list="#formScope.fieldNames#" index="I">
			<cftry>
				<!--- if there are form subViews with a corresponding ORM setter then we call the setter
						otherwise, the catch just ignores them
				--->
				<cfset evaluate("thisObject.set#I#(formScope.#I#)")>

				<cfcatch></cfcatch>
			</cftry>
		</cfloop>

		<!--- triggerEvent will make the call implicitly to try to persist this ORM object --->
		<cf_triggerEvent event="save#formScope.ORM#" objectName="#formScope.ORM#" object=#thisObject#>

		<cfreturn>
	</cffunction>
<!---  --->
	<cffunction name="listToStruct" returntype="Struct">
		<cfargument name="thisList" required="true" type="string">
		<cfargument name="delim" default="/" required="false" type="string">

		<cfset I = "">
		<cfset result = structNew()>

		<cfif listLen(arguments.thisList)>
			<cfloop from="1" to="#listLen(thisList)#" index="I" step="2">
				<cfif NOT findNoCase("_CF", I)>
					<cfset key = trim(listGetAt(thisPath, I, "#arguments.delim#"))>
					<cfset value = trim(listGetAt(thisPath, I + 1, "#arguments.delim#"))>

					<cfset result["#key#"] = value>
				</cfif>
			</cfloop>
		</cfif>

		<cfreturn result>
	</cffunction>
<!---  --->
	<cffunction name="structToArgs" returntype="String">
		<cfargument name="A" required="true" type="struct">

		<cfset I = "">
		<cfset result = "">

		<cfif structCount(arguments.A)>
			<cfloop list="#structKeyList(arguments.A)#" index="I">
				<cfif NOT findNoCase("_CF", I)>
					<cfset result &= "#I#='#structFind(arguments.A, I)#',">
				</cfif>
			</cfloop>

			<cfif len(result)>
				<cfset result = left(result, len(result) - 1)>	<!--- take off the last delimiter --->
			</cfif>
		</cfif>

		<cfreturn result>
	</cffunction>
<!---  --->
	<cffunction name="structToList" returntype="String">
		<cfargument name="A" required="true" type="struct">

		<cfset I = "">
		<cfset result = "">

		<cfif structCount(arguments.A)>
			<cfloop list="#structKeyList(arguments.A)#" index="I">
				<cfif NOT findNoCase("_CF", I)>
					<cfset result = listAppend(result, I, "/")>
					<cfset result = listAppend(structFind(arguments.A, I), I, "/")>
				</cfif>
			</cfloop>
		</cfif>

		<cfreturn result>
	</cffunction>
<!---  --->
	<cffunction name="structToURL" returntype="String">
		<cfargument name="A" required="true" type="struct">

		<cfset I = "">
		<cfset result = "">

		<cfif structCount(arguments.A)>
			<cfloop list="#structKeyList(arguments.A)#" index="I">
				<cfset result &= "#I#='#structFind(arguments.A, I)#'&">
			</cfloop>

			<cfset result = left(result, len(result) - 1)>	<!--- take off the last delimiter --->
		</cfif>

		<cfreturn result>
	</cffunction>
<!--- END FRAMEWORK UTILITY FUNCTIONS --->

<!--- START FRAMEWORK HELPER FUNCTIONS --->
	<cffunction name="bindController" output="true" returntype="String" hint="Returns a properly formatted string for a cfajaxproxy bind attribute">
		<cfargument name="funcName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">

		<cfoutput>URL:index.cfm?com=#arguments.funcName#&#structToURL(arguments.values)#</cfoutput>
	</cffunction>
<!--- [, {values:{values}, container:"containerName", view:"viewName"}] --->
	<cffunction name="bindSubView" output="true" returntype="String" hint="Returns a properly formatted string for a cfdiv bind attribute">
		<cfargument name="subViewName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">

		<cfoutput>URL:index.cfm?subView=#arguments.subViewName#&#structToURL(arguments.values)#</cfoutput>
	</cffunction>
<!---  --->
	<cffunction name="controllerCFC" output="false" returntype="String" hint="returns the current controller CFC's dot path">
		<cfreturn "view.#session.view#.controller">
	</cffunction>
<!---  --->
	<cffunction name="displayCFC" output="false" returntype="String" hint="returns the current display CFC's dot path">
		<cfreturn "view.#session.view#.display">
	</cffunction>
<!---  --->
	<cffunction name="eventResponse" returntype="Any" hint="returns the response for the named event">
		<cfargument name="eventName" required="true" type="string">

		<cfreturn request.event.response["#arguments.eventName#"]>
	</cffunction>
<!---  --->
	<cffunction name="gotoView" output="true" returntype="void" hint="Redirects to another view">
		<cfargument name="viewName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">

		<cflocation addtoken="false" url="index.cfm/view/#arguments.viewName#/#structToList(arguments.values)#">
	</cffunction>
<!---  --->
	<cffunction name="HREFview" output="true" returntype="String" hint="Produces an anchor-link to another view">
		<cfargument name="viewName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">

		<cfoutput>#application.URL#/index.cfm/#arguments.viewName#?#structToURL(arguments.values)#</cfoutput>
	</cffunction>
<!---  --->
	<cffunction name="HREFsubView" output="true" returntype="String" hint="Produces an anchor-link that updates a sub-view">
		<cfargument name="subViewName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">

		<cfoutput>#application.URL#/index.cfm?subView=#arguments.subViewName#&#structToURL(arguments.values)#</cfoutput>
	</cffunction>
<!---  --->
	<cffunction name="setEventResponse" returntype="void" hint="Sets an event response, available in the current request">
		<cfargument name="eventName" required="true" type="string">
		<cfargument name="response" required="true" type="any">

		<cfset request.event.response["#arguments.eventName#"] = arguments.response>
	</cffunction>
<!---  --->
	<cffunction name="subView" output="true" returntype="String">
		<cfargument name="subViewName" required="true" type="string">
		<cfargument name="values" default="#structNew()#" required="false" type="struct">
		<cfargument name="tagName" default="div" required="false" type="string">
		<cfargument name="id" default="#arguments.subViewName#Container" required="false" type="string">
		<cfargument name="class" default="" required="false" type="string">
		<cfargument name="initFill" default="true" required="false" type="boolean">

		<cfoutput>
			<#arguments.tagName# id="#arguments.id#Container" class="#arguments.class#">
				<cfif initFill>
					#evaluate("session.display.#arguments.subViewName#(#structToArgs(arguments.values)#)")#
				</cfif>
			</#arguments.tagName#>
		</cfoutput>
	</cffunction>
<!--- END FRAMEWORK HELPER FUNCTIONS --->
</cfcomponent>